from lxml import etree

html = """
  <ul>
    <li class="item-0"><a href="link1.html">first item</a></li>
    <li class="item-1" text='kangbazi'><a href="link2.html">second item</a></li>
    <li class="item-active"><a href="link3.html">three item</a></li>
    <li class="item-3"><a href="link4.html">four item</a></li>
    <li class="item-4"><a href="link5.html">five item</a></li>
    <li class="item-5"><a href="link6.html">six item</a></li>
</ul>




"""

text = etree.HTML(html)
# print(text.xpath("//li/@class")) #li下面所有的class
# print(text.xpath("//li/@text"))
# print(text.xpath("//li/a/@href=\"link6.html\""))  #判断是否有link6.html
# #返回的是true 和false

# print(text.xpath("//li[1]/a/text()"))
# print(text.xpath("//li[last()]/a/text()")) #最后一个
print(text.xpath("//li[last()-1]/a/text()")) #倒数第二个
print(text.xpath("//li[position()>3]/a/text()")) #大于3的
print(text.xpath("//*[@text=\"kangbazi\"]/a/text()")) #选取text=kangbazi的元素